package com.chanceit.ssss.activity;

import org.gl.android.activity.ImageUploadActivity;
import org.gl.customview.ViewPager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.WindowManager;

import com.chanceit.ssss.adapters.SectionsPagerAdapter;
import com.chanceit.ssss.fragments.MessageCenterMessageListFragment;
import com.chanceit.ssss.fragments.OnFragmentEvent;

public class MessageBoxActivity extends BaseFragmentActivity implements
		OnFragmentEvent {
	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		int inputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
		inputMode = inputMode
				| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
		getWindow().setSoftInputMode(inputMode);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_message_box);

		if (findViewById(R.id.fragment_container) != null) {

			// However, if we're being restored from a previous state,
			// then we don't need to do anything and should return or else
			// we could end up with overlapping fragments.
			if (savedInstanceState != null) {
				return;
			}
			// // Create an instance of ExampleFragment
			// HeadlinesFragment firstFragment = new HeadlinesFragment();
			//
			// // In case this activity was started with special instructions
			// from
			// // an Intent,
			// // pass the Intent's extras to the fragment as arguments
			// firstFragment.setArguments(getIntent().getExtras());
			//
			// // Add the fragment to the 'fragment_container' FrameLayout
			Fragment fragment = new MessageCenterMessageListFragment();
			getSupportFragmentManager().beginTransaction()
					.add(R.id.fragment_container, fragment).commit();
		}
	}

	@Override
	public void onArticleSelected(int position) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onFragmentClick(View view) {
		switch (view.getId()) {
		case R.id.pickImage:
			Intent intent = new Intent();
			intent.setClass(this, ImageUploadActivity.class);
			if (view.getTag()!=null) {
				intent.putExtra(ImageUploadActivity.LocalImageUrl,view.getTag().toString());
			}
			startActivityForResult(intent,
					ImageUploadActivity.RequestCode_ImageUpload);
			break;
		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == Activity.RESULT_OK) {
			if (data != null) {
				((MessageCenterMessageListFragment) getSupportFragmentManager()
						.findFragmentById(R.id.fragment_container))
						.receiveImageUploadResult(
								data.getStringExtra(ImageUploadActivity.ImageUploadResuleExtraKey),
								data);
			}
		} else {

		}
	}
}
